#
# Test Soul::Match 
#

require 'soul/match'
require 'soul/iterator'
require 'test/unit'

class TestMatch < Test::Unit::TestCase
	
	include Soul::Matches

	def iter(str)
		Soul::Iterator.new(str)
	end		

	def test_unary
		assert(eol.include?("\n"))
		assert(any.include?("A"))
		assert(nothing.include?(nil))
		assert(space.include?(" "))
		assert(digit.include?("8"))
		assert((~digit).include?("a"))
	end

	def test_one_or_more
		i = iter("0123456789sd")
		assert((+digit).include? i)
		assert(i.index == 10)
		assert((+digit).include? "9")
		assert((+digit).include?("s") == false)
	end

	def test_sequence
		i = iter("0a2")
		m = digit >> ~digit >> digit
		assert(m.include?(i))
		assert(m.include?(iter("012")) == false)
		assert(m.include?("9") == false)
	end

	def test_zero_or_more
		i = iter("0123")
		m = !digit
		assert(m.include?("a"))
		assert(m.include?(i))
	end

	def test_zero_or_one
		i = iter("0123")
		m = -digit
		assert(m.include?("a"))
		assert(m.include?("1"))
		assert(m.include?(i))
		assert(i.index==1)
	end

end
